package com.example.mapstructdemo;


import org.apache.commons.beanutils.Converter;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Spring 自带的BeanUtils在拷贝对象属性中含有日期类型的无法进行拷贝，故实现转换器
 */
public class SpringCustomerDateConverter implements Converter {

    private final static SimpleDateFormat DATE_FORMATE = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public Object convert(Class classzz, Object object) {
        if (classzz.equals(java.util.Date.class)) {
            System.out.println("进行日期格式转换。。。");
            try {
                return DATE_FORMATE.parse(object.toString());
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }
}
